// 班级数据类型定义
export interface ClassData {
  id: string;
  className: string;
  description: string;
  major: number;
  counselor: string;
  lecturer: string;
  studentCount: number;
}

// 模拟数据
export const mockClasses: ClassData[] = [
  {
    id: '1',
    className: '2411A',
    description: '2411A',
    major: 2,
    counselor: '赵导员',
    lecturer: '李教授',
    studentCount: 2
  },
  {
    id: '2',
    className: '2411B',
    description: '2411B',
    major: 2,
    counselor: '赵导员',
    lecturer: '王老师',
    studentCount: 5
  },
  {
    id: '3',
    className: '2412A',
    description: '2412A',
    major: 1,
    counselor: '钱导员',
    lecturer: '王老师',
    studentCount: 2
  },
  {
    id: '4',
    className: '2412B',
    description: '2412B',
    major: 1,
    counselor: '钱导员',
    lecturer: '李教授',
    studentCount: 4
  }
];

// 模拟API调用函数
export const classService = {
  // 获取班级列表
  getClasses: async (): Promise<ClassData[]> => {
    // 模拟网络延迟
    await new Promise(resolve => setTimeout(resolve, 500));
    return [...mockClasses];
  },
  
  // 添加班级
  addClass: async (classData: Omit<ClassData, 'id'>): Promise<ClassData> => {
    await new Promise(resolve => setTimeout(resolve, 300));
    const newClass: ClassData = {
      ...classData,
      id: Date.now().toString()
    };
    mockClasses.push(newClass);
    return newClass;
  },
  
  // 更新班级
  updateClass: async (id: string, classData: Partial<ClassData>): Promise<ClassData | null> => {
    await new Promise(resolve => setTimeout(resolve, 300));
    const index = mockClasses.findIndex(c => c.id === id);
    if (index !== -1) {
      mockClasses[index] = { ...mockClasses[index], ...classData };
      return mockClasses[index];
    }
    return null;
  },
  
  // 删除班级
  deleteClass: async (id: string): Promise<boolean> => {
    await new Promise(resolve => setTimeout(resolve, 300));
    const index = mockClasses.findIndex(c => c.id === id);
    if (index !== -1) {
      mockClasses.splice(index, 1);
      return true;
    }
    return false;
  }
};